import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import LayoutComponent from "@/layout/index.vue";
import NotFoundComponent from "@/router/404.vue";
import { Component } from "vue";

const Layout = LayoutComponent as unknown as Component
const NotFound = NotFoundComponent as unknown as Component
const routes: Readonly<RouteRecordRaw[]> = [
  {
    path: '/',
    component: Layout,
    meta: {
      title: "登录",
      hidden: true,
    },
    redirect: '/login',
    children: [
      {
        path: "/login",
        component: () => import('@/views/login/login.vue'),
      },
      {
        path: "/register",
        component: () => import('@/views/login/register.vue'),
      },
    ],
  },
  {
    path: "/home",
    redirect: '/statistical',
    component: Layout,
    meta: {
      title: "首页",
    },
    children: [
      {
        path: "/statistical",
        meta: {
          title: "营业统计",
        },
        component: () => import("@/views/home/statistical.vue"),
      },
      {
        path: "/statistical/put",
        meta: {
          title: "入库分析",
        },
        component: () => import("@/views/home/ProductPut.vue"),
      },
      {
        path: "/statistical/out",
        meta: {
          title: "出库分析",
        },
        component: () => import("@/views/home/ProductOut.vue"),
      },
      {
        path: "/statistical/stock",
        meta: {
          title: "库存分析",
        },
        component: () => import("@/views/home/ProductStock.vue"),
      },
      {
        path: "/setting",
        meta: {
          title: "个人中心",
          hidden: true,
        },
        component: () => import('@/views/home/setting.vue'),
      },
    ],
  },
  {
    path: "/product",
    component: Layout,
    meta: {
      title: "商品",
    },
    children: [
      {
        path: "/product/index",
        meta: {
          title: "商品",
        },
        component: () => import("@/views/product/index.vue"),
      },
      {
        path: "/product/detail",
        meta: {
          title: "详情",
          hidden: true,
        },
        component: () => import("@/views/product/detail.vue"),
      },
    ],
  },
  {
    path: "/system",
    component: Layout,
    children: [
      {
        path: "/logger",
        meta: {
          title: "日志调试",
          hidden: true,
        },
        component: () => import("@/views/system/log.vue"),
      },
    ],
  },
  {
    path: '/:pathMatch(.*)*',
    meta: {
      title: "NotFound",
      hidden: true,
    },
    component: NotFound
  }
];

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});

export default router;
